package com.craney.testTextField
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.TextEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	public class CaptureUserInput
	{
		private var input:TextField = new TextField();
		
		private var output:TextField = new TextField();
		
		private var parentSprite:Sprite;
		
		private var focusFirst:Boolean = false;
		
		public function CaptureUserInput(ps:Sprite)
		{
			input.border = true;
			input.background = true;
			input.type = TextFieldType.INPUT;
			input.displayAsPassword = true;
			
			input.text = "Please input:";
			
			input.addEventListener(TextEvent.TEXT_INPUT, textInput);
			
			
			parentSprite = ps;
			ps.addChild(input);
			parentSprite.addChild(output);
			output.border = true;
			output.background = true;
			
			output.x = 250;
			
			input.addEventListener(FocusEvent.FOCUS_IN, clean);
			input.addEventListener(FocusEvent.FOCUS_OUT, doSth);
		}
		private function doSth(event:Event):void
		{
			focusFirst = false;
		}
		
		private function clean(event:Event):void
		{
			if(!focusFirst) 
			{
				input.text = "";
				focusFirst = true;
			}
		}
		
		
		private function textInput(event:Event):void
		{
			var str:String = (event.target as TextField).text;
			trace(str);
			output.text = str;
		}

	}
}